import requests

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
    , 'Accept-Encoding': 'gzip, deflate, br'
    , 'Accept-Language': 'en,zh-CN;q=0.9,zh;q=0.8'
    , 'Cache-Control': 'max-age=0'
    , 'Connection': 'keep-alive'
    , 'Range': 'bytes=0-600'
    , 'Sec-Fetch-Dest': 'document'
    , 'Sec-Fetch-Mode': 'navigate'
    , 'Sec-Fetch-Site': 'none'
    , 'Sec-Fetch-User': '?1'
    , 'Upgrade-Insecure-Requests': '1'
    ,
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
}

url = "url"

r = requests.get(url, headers=headers)
v_url = r.url
print(v_url)
headers_v = {
    'Accept': '*/*'
    , 'Accept-Encoding': 'identity;q=1, *;q=0'
    , 'Accept-Language': 'en,zh-CN;q=0   .9,zh;q=0.8'
    , 'Cache-Control': 'max-age=0'
    , 'Connection': 'keep-alive'
    , 'Host': 'v2.goovvg.com:3002'
    , 'Range': 'bytes=0-'
    , 'Sec-Fetch-Dest': 'video'
    , 'Sec-Fetch-Mode': 'no-cors'
    , 'Sec-Fetch-Site': 'same-origin'
    ,
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
    , 'Referer': v_url
}
r = requests.get(v_url, headers=headers_v, stream=True)

with open('test.mp4', "wb") as mp4:
    for chunk in r.iter_content(chunk_size=1024 * 1024):
        print(chunk)
        if chunk:
            mp4.write(chunk)
            print('writing...')

print("下载结束")
